/**
 * @param {number[]} arr
 * @return {number}
 */
export var peakIndexInMountainArray = function (arr) {
  let left = 1,
    right = arr.length - 2
  let ans = 0
  while (left <= right) {
    const mid = (left + right) >> 1
    if (arr[mid] > arr[mid + 1]) {
      right = mid - 1
      ans = mid
    } else {
      left = mid + 1
    }
  }
  return ans
}
